import request from "@/axios"
//幻灯片
export function bannerList(id) {
    let url = '/api/home/banner/'
    if(id!=undefined){
        url += id
    }
    return request.get(url)
}
//推荐产品
export function topList(page,id,saleType) {
    let limit = 6
    if(id==undefined||id==0){
        id=null
    }
    let url = '/api/goods/list'
    let params = {
        limit:limit,
        page:page,
        type:id,
        saleType
    }
    return request.get(url,{params})
}

//产品详情
export function detail(id) {
    let url = '/api/home/goods/info/'+id
    return request.get(url)
}

//菜单栏
export function getMenubarList() {
    let url = '/api/saleTypes/list'
    return request.get(url)
}

//tabBar分类
export function getTabBarType(){
    let url ='/api/mallType/findBigType'
    return request.get(url)
}

//获取头条推荐商品
export  function getHeadGoods(id){
    let url = '/api/mallType/findByPid/'+id
    return request.get(url)
}

//点击导航进入页面，获取商品列表
export function getSearchGoodsList(page,type,saleType){
    let url =
        `/api/saleTypes/BySaleTypeId?page=${page}&limit=10&type=0&saleType=${saleType}`
    return request.get(url)
}
export function getShopList(page,shopName) {
    let url =
        `/api/saleTypes/BySaleTypeId?page=${page}&limit=5&type=0&saleType=13&shopName=${shopName||''}`
    return request.get(url)
}

export function getHeadLineList(id,page){
    let url=`/api/mallType/queryMallGoods/${id}/${page}/${10}`
    return request.get(url)
}

export function getSearchList(name,page,limit){
    let url=`/api/goods/search?name=${name}&page=${page}&limit=${limit}`
    return request.get(url)
}

export function getDistance(lat1, lng1, lat2, lng2) {
    lat1 = lat1 || 0;
    lng1 = lng1 || 0;
    lat2 = lat2 || 0;
    lng2 = lng2 || 0;

    var rad1 = lat1 * Math.PI / 180.0;
    var rad2 = lat2 * Math.PI / 180.0;
    var a = rad1 - rad2;
    var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;

    var r = 6378137;
    return r * 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(rad1) * Math.cos(rad2) * Math.pow(Math.sin(b / 2), 2)))
}

export function getDailyList(page) {
    let url = 'api/saleTypes/daily'
    let params = {page,limit:5}
    return request.get(url,{params})
}


